<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>localStorage</title> 
</head>
<body>
    <!-- 准备一个容器 -->
    <h1>localStorage</h1>
    <button onclick="saveData()" >点我保存一个数据</button>
    <button onclick="getData()" >点我读取一个数据</button>
    <button onclick="deleteData()" >点我删除一个数据</button>
    <button onclick="deleteAllData()" >点我清空一个数据</button>
</body>
<script type="text/javascript" > 
    let p = {name:'张三', age:18}
    function saveData(){
        localStorage.setItem('msg', '你好啊')
        localStorage.setItem('p', JSON.stringify(p))
    }

    function getData(){
        console.log(JSON.parse(localStorage.getItem('p')))
    }

    function deleteData(){
        localStorage.removeItem('msg')
    }

    function deleteAllData(){
        localStorage.clear()
    }
</script>
</html>